package dk.itu.samd.group2.tagapastry.messages.forwardStrategies;

import java.util.Vector;

import dk.itu.samd.group2.tagapastry.ChildrenMapper;
import dk.itu.samd.group2.tagapastry.IndexRelative;
import dk.itu.samd.group2.tagapastry.TagapastryImpl;
import dk.itu.samd.group2.tagapastry.messages.IndexMsg;

public class SinglecastReturnToParentStrategy implements ForwardStrategy {

	private String hash;
	
	public SinglecastReturnToParentStrategy(String hash) {
		this.hash = hash;
	}
	
	@Override
	public void forward(Vector<IndexRelative> children, TagapastryImpl tagaImpl, IndexMsg msg) {
		
		ChildrenMapper mapper = new ChildrenMapper();
				
		int childIndex = mapper.get(children.get(0).getTag(), hash);
		
		IndexRelative child = children.get(childIndex);
		
		IndexMsg msgForChild = msg.cloneForChild(child);
		
		child.bufferOrForward(msgForChild, tagaImpl);
		
	}

}
